package com.example.pattern.flyweight;

/**
 * 应用
 *
 * @author FM_南风
 * @date 2024/6/27
 */
public class FlyweightClient {
 private static final String[] colors = {"红", "绿", "蓝"};

 public static void main(String[] args) {
  for (int i = 0; i < 20; ++i) {
   FlyweightClass circle = (FlyweightClass) FlyweightFactory.getCircle(getRandomColor());
   circle.setX(getRandomX());
   circle.setY(getRandomY());
   circle.setRadius(100);
   circle.draw();
  }
 }

 private static String getRandomColor() {
  return colors[(int) (Math.random() * colors.length)];
 }

 private static int getRandomX() {
  return (int) (Math.random() * 100);
 }

 private static int getRandomY() {
  return (int) (Math.random() * 100);
 }
}
